home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / CHEMPLOT.ZIP / TPlot / TChart Demo / TChartNormal1.pas < prev   
Pascal/Delphi Source File  |  2001-02-06  |  7KB  |  277 lines

  1. unit TChartNormal1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ImgList, Menus, Grids, ExtCtrls, StdCtrls,
  8.   Buttons, ActnList, ToolWin, ComCtrls, 
  9.  
  10.   VEdit, NEdit,
  11.   Plot, Plotdefs, PlotMenu, PlotImageList, Data, TeeProcs, TeEngine, Chart,
  12.   Series;
  13.  
  14. type
  15.   TMainForm = class(TForm)
  16.     Panel1: TPanel;
  17.     StringGrid1: TStringGrid;
  18.     MinNEdit: TNEdit;
  19.     Label1: TLabel;
  20.     Label2: TLabel;
  21.     MaxNEdit: TNEdit;
  22.     Label3: TLabel;
  23.     StepSizeNEdit: TNEdit;
  24.     Label4: TLabel;
  25.     MeanNEdit: TNEdit;
  26.     Label5: TLabel;
  27.     StdDevNEdit: TNEdit;
  28.     GoBitBtn: TBitBtn;
  29.     GoCrazyBitBtn: TBitBtn;
  30.     CrazyTimer: TTimer;
  31.     ClearAllBitBtn: TBitBtn;
  32.     NoisyBitBtn: TBitBtn;
  33.     TraceBitBtn: TBitBtn;
  34.     TypeBitBtn: TBitBtn;
  35.     Chart1: TChart;
  36.     StatusBar1: TStatusBar;
  37.     Series1: TLineSeries;
  38.     procedure ClearAllBitBtnClick(Sender: TObject);
  39.     procedure GoBitBtnClick(Sender: TObject);
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure PlotMenu1ExitMenuItemClick(Sender: TObject);
  42.     procedure NoisyBitBtnClick(Sender: TObject);
  43.     procedure GoCrazyBitBtnClick(Sender: TObject);
  44.     procedure CrazyTimerTimer(Sender: TObject);
  45.     procedure Plot1FileOpen(Sender: TObject; TheFile: String);
  46.     procedure TraceBitBtnClick(Sender: TObject);
  47.     procedure TypeBitBtnClick(Sender: TObject);
  48.   private
  49.     //Chart1: TPlot;
  50.     //PlotMenu1: TPlotMenu;
  51.     Revolutions,
  52.     StartWidth,
  53.     StartHeight: Integer;
  54.     Angle,
  55.     AngleInc: Single;
  56.   public
  57.     { Public declarations }
  58.   end;
  59.  
  60. var
  61.   MainForm: TMainForm;
  62.  
  63. implementation
  64.  
  65. {$R *.DFM}
  66.  
  67. const
  68.   RADIUS = 50.0;
  69.  
  70. procedure TMainForm.FormCreate(Sender: TObject);
  71. {var
  72.   PlotImageList : TPlotImageList;}
  73. begin
  74.   //Chart1 := TPlot.Create(Self);
  75.   Chart1.Parent := MainForm;
  76.   Chart1.Align := alClient;
  77.   {Chart1.PlotType := ptXY;
  78.   Chart1.NoSeries := 2;
  79.   Chart1.MakeDummyData(20);}
  80.   //PlotMenu1.Plot := Chart1;
  81.   StringGrid1.Cells[0, 0] := 'Test:';
  82.   StringGrid1.Cells[0, 1] := 'Score:';
  83.   StringGrid1.ColWidths[0] := 60;
  84.   //PlotImageList := TPlotImageList.Create(Self);
  85.   //PlotImageList.Free;
  86.   //GoBitBtnClick(Sender);
  87.   //PlotActionList1.Plot := Chart1;
  88. end;
  89.  
  90. procedure TMainForm.ClearAllBitBtnClick(Sender: TObject);
  91. var
  92.   i: Integer;
  93. begin
  94.   for i := 0 to Chart1.SeriesList.Count-1 do
  95.   begin
  96.     Chart1.Series[i].Clear;
  97.   end;
  98.  
  99.   for i := 1 to StringGrid1.ColCount-1 do
  100.   begin
  101.     StringGrid1.Cells[i, 0] := '';
  102.     StringGrid1.Cells[i, 1] := '';
  103.   end;
  104. end;
  105.  
  106. procedure TMainForm.GoBitBtnClick(Sender: TObject);
  107. var
  108.   X, Y: Single;
  109.   Mean: Single;
  110.   StdDev: Single;
  111.   Min: Single;
  112.   Max: Single;
  113.   StepSize: Single;
  114.   TheSeries: Integer;
  115.   TheScore: Single;
  116.   i: Integer;
  117.   FStartTime:          Int64; {TLargeInteger;}
  118.   FFinishTime:         Int64;
  119.   FFrequency:          Int64;
  120.   ElapsedTime: Double;
  121. begin
  122.   Screen.Cursor := crHourGlass;
  123.   QueryPerformanceFrequency(FFrequency); {counts per second}
  124. {get the starting time:}
  125.   QueryPerformanceCounter(FStartTime); { LARGE_INTEGER}
  126.  
  127.   for i := 0 to Chart1.SeriesList.Count-1 do
  128.   begin
  129.     Chart1.Series[i].Clear;
  130.   end;
  131.  
  132.   Mean := MeanNEdit.AsReal;
  133.   StdDev := StdDevNEdit.AsReal;
  134.   Min := MinNEdit.AsReal;
  135.   Max := MaxNEdit.AsReal;
  136.   StepSize := StepSizeNEdit.AsReal;
  137.  
  138. {Set the axes:}
  139.   Chart1.BottomAxis.Maximum := Max;
  140.   Chart1.BottomAxis.Minimum := Min;
  141.   Chart1.LeftAxis.Minimum := 0;
  142.   //Chart1.LeftAxis.Intercept := 0;
  143.  
  144.   X := Min;
  145.   while (X <= Max) do
  146.   begin
  147.     Y := Exp(-Sqr((X-Mean)/(2*StdDev))) /
  148.       Sqrt(2*Pi*StdDev);
  149. {Don't fire any events, and don't adjust axes:}
  150.     Chart1.SeriesList[0].AddXY(X, Y);
  151.     X := X + StepSize;
  152.   end;
  153.  
  154.   {Chart1.YAxis.Min := Chart1.Series[0].YMin;}
  155.   //Chart1.LeftAxis.Maximum := Chart1.Series[0].YMax;
  156.  
  157.   {for i := 1 to StringGrid1.ColCount-1 do
  158.   begin
  159.     if (Length(StringGrid1.Cells[i, 0]) > 0) then
  160.     begin
  161.       if (Length(StringGrid1.Cells[i, 1]) > 0) then
  162.       begin
  163.         try
  164.           TheScore := StrToFloat(StringGrid1.Cells[i, 1]);
  165.           TheSeries := Chart1.Add(-1);
  166.           Chart1[TheSeries].Name := StringGrid1.Cells[i, 0];
  167.           Chart1[TheSeries].AddPoint(TheScore, Chart1.YAxis.Min, TRUE, TRUE);
  168.           Chart1[TheSeries].AddPoint(TheScore, Chart1.YAxis.Max, TRUE, TRUE);
  169.           Chart1[TheSeries].Visible := TRUE;
  170.           Chart1[TheSeries].Symbol := TSymbol(i mod (1+Ord(sDownTriangle)));
  171.         finally
  172.         end;
  173.       end;
  174.     end;
  175.   end;}
  176. {get the finishing time:}
  177.   QueryPerformanceCounter(FFinishTime); { LARGE_INTEGER}
  178. {take difference and convert to ms:}
  179.   ElapsedTime := 1000 * (FFinishTime - FStartTime) / FFrequency;
  180.   StatusBar1.SimpleText := Format('Drawing %d points takes %g ms',
  181.     [Chart1.Series[0].Count, ElapsedTime]);
  182.   Screen.Cursor := crDefault;
  183. end;
  184.  
  185. procedure TMainForm.PlotMenu1ExitMenuItemClick(Sender: TObject);
  186. begin
  187.   Close;
  188. end;
  189.  
  190. procedure TMainForm.NoisyBitBtnClick(Sender: TObject);
  191. begin
  192.   //Chart1.MakeDummyData(100);
  193. end;
  194.  
  195. procedure TMainForm.GoCrazyBitBtnClick(Sender: TObject);
  196. begin
  197.   if (CrazyTimer.Enabled) then
  198.   begin
  199.     CrazyTimer.Enabled := FALSE;
  200.     GoCrazyBitBtn.Caption := 'Go Crazy';
  201.     TraceBitBtn.Enabled := TRUE;
  202.   end
  203.   else
  204.   begin
  205.     Revolutions := 0;
  206.     StartWidth := Width;
  207.     StartHeight := Height;
  208.     Angle := 0;
  209.     AngleInc := 4 * Pi / 180;
  210.     GoCrazyBitBtn.Caption := 'Enough !';
  211.     CrazyTimer.Enabled := TRUE;
  212.     TraceBitBtn.Enabled := FALSE;
  213.   end;
  214. end;
  215.  
  216. procedure TMainForm.CrazyTimerTimer(Sender: TObject);
  217. begin
  218.   Width := StartWidth + Round(RADIUS * Sin(Angle));
  219.   Height := StartHeight + Round(RADIUS * Cos(Angle));
  220.   Angle := Angle + AngleInc;
  221.   Inc(Revolutions);
  222.   StatusBar1.SimpleText := IntToStr(Revolutions);
  223. end;
  224.  
  225. procedure TMainForm.Plot1FileOpen(Sender: TObject; TheFile: String);
  226. var
  227.   TheTitle: String;
  228. begin
  229.   TheTitle := ExtractFileName(Application.ExeName);
  230.   TheTitle := Copy(TheTitle, 1, Length(TheTitle)-4);
  231.   TheTitle := TheTitle + ' - ' + ExtractFileName(TheFile);
  232.   Application.Title := TheTitle;
  233.   MainForm.Caption := TheTitle;
  234. end;
  235.  
  236. procedure TMainForm.TraceBitBtnClick(Sender: TObject);
  237. begin
  238.   //Chart1.Trace;
  239. end;
  240.  
  241. procedure TMainForm.TypeBitBtnClick(Sender: TObject);
  242. var
  243.  ThePlotType: Integer;
  244. begin
  245.   {ThePlotType := Ord(Chart1.PlotType);
  246.   ThePlotType := (ThePlotType+1) mod (Ord(High(TPlotType))+1);
  247.   Chart1.SeriesList.ClearSeries;
  248.   Chart1.PlotType := TPlotType(ThePlotType);
  249.   case Chart1.PlotType of
  250.     ptXY: Chart1.MakeDummyData(100);
  251.     ptError, ptMultiple: Chart1.MakeDummyData(20);
  252.     ptColumn, ptStack, ptNormStack: Chart1.MakeDummyData(10);
  253.     ptPie: Chart1.MakeDummyData(10);
  254.     ptPolar:
  255.       begin
  256.         Chart1.XAxis.Min := -10;
  257.         Chart1.XAxis.Max := 10;
  258.         Chart1.YAxis.Min := -10;
  259.         Chart1.YAxis.Max := 10;
  260.         Chart1.MakeDummyData(20);
  261.       end;
  262.     pt3DWire, pt3DSurface:
  263.       begin
  264.         Chart1.XAxis.Min := 0;
  265.         Chart1.XAxis.Max := 10;
  266.         Chart1.YAxis.Min := 0;
  267.         Chart1.YAxis.Max := 10;
  268.         Chart1.MakeDummyData(20);
  269.         Chart1.NoSeries := 8;
  270.         Chart1.MakeDummyData(10);
  271.       end;
  272.   else ;
  273.   end;}
  274. end;
  275.  
  276. end.
  277.